<?php

/**
 * @author Watanabex
 * @copyright 2012
 * masmonitos_imagenes DAO
 */
require('to/Masmonitos_Imagen.php');

class masmonitos_imagenesDAO{
	const SEL_BY_ALBUM = "SELECT * FROM masmonitos_imagenes WHERE status = 'A' AND album_id = %d ORDER BY id ASC;";
	const SEL_TOP3 =  "SELECT * FROM masmonitos_imagenes WHERE status = 'A' AND album_id = %d ORDER BY id ASC LIMIT 3;";
	
	public static function getByAlbum($album_id){
		$sSql = self::SEL_BY_ALBUM;
		
		$DB = DBFunctions::getInstance();
		$arrNotas = $DB->execSelect($sSql, array($album_id));
		
		return self::populate($arrNotas);
	}
	
	public static function getTop3(){
		$sSql = self::SEL_TOP3;
		
		$DB = DBFunctions::getInstance();
		$arrNotas = $DB->execSelect($sSql, array());
		
		return self::populate($arrNotas);
	}	
	
	/*This function get's the result array and builds a masmonitos_imagenes array object
	 * @param array masmonitos_imagenes result
	 * @returns array with masmonitos_imagenes objects */
	private static function populate($arrMasmonitosImagenes){
		
		$objMasmonitosImagenes = array();
		
		foreach($arrMasmonitosImagenes as $A){
			$objMasmonitosImagen = new Masmonitos_Imagen();
			$objMasmonitosImagen->setID($A["id"]);
			$objMasmonitosImagen->setAlbumID($A["album_id"]);
			$objMasmonitosImagen->setImagen($A["imagen"]);
			$objMasmonitosImagen->setStatus($A["status"]);
			
			array_push($objMasmonitosImagenes, $objMasmonitosImagen);
		}
		return $objMasmonitosImagenes;
	}
}